package com.appforged.AppForged;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.appforged.AppForged1.R;

public class Menu extends ListActivity {

	// array list for list
	String classes[] = { "Calc", "TextPlay", "Email", "Camera", "Data",
			"GFX", "GFXSurface", "SoundStuff","Slider","to be","to be","to be" };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		//remove bars
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		setListAdapter(new ArrayAdapter<String>(Menu.this,
				android.R.layout.simple_list_item_1, classes));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		// String name = classes[1];
		try {
			Class ourClass = Class.forName("com.appforged.AppForged."
					+ classes[position]);

			Intent ourIntent = new Intent(Menu.this, ourClass);
			startActivity(ourIntent);

		} catch (ClassNotFoundException e) {

			// set up alert message box
			AlertDialog.Builder dlgAlert = new AlertDialog.Builder(Menu.this);
			// exit
			dlgAlert.setMessage("NO APP");
			dlgAlert.setTitle("Error");
			// if ok
			dlgAlert.setPositiveButton("OK",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

							// Splash.this.finish();

						}
					});
			dlgAlert.setCancelable(true);
			dlgAlert.create().show();

			e.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);

		MenuInflater blowUp = getMenuInflater();
		blowUp.inflate(R.menu.cool_menu, menu);
		return true;

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.aboutUs:
			Intent i = new Intent("com.appforged.AppForged.ABOUT");
			startActivity(i);
			break;
		case R.id.preferences:
			Intent p = new Intent("com.appforged.AppForged.PREFS");
			startActivity(p);
			break;
		case R.id.exit:
			finish();
			break;

		}
		return false;
	}

}
